home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Champak 29
/
Volume 29 - JOGO DISK .iso
/
Games
/
jungle_adventure.swf
/
scripts
/
__Packages
/
BouncingObject.as
next >
Wrap
Text File
|
2006-11-29
|
4KB
|
136 lines
class BouncingObject extends SSObject
{
var assetID = "Spider";
var healthValue = -0.2;
var classID = SSGlobal.CLSID_MOBILEOBJECT;
var collisionMask = SSGlobal.CLSID_SHAPE | SSGlobal.CLSID_MAINCHAR;
var jumpStrength = 300;
var gravity = SSGlobal.GRAVITY * 0.5;
var vulnerable = false;
var contactTimeAllow = 1;
var contactTime = 0;
var collision = false;
var immobilized = 0;
var immobilizeTime = 5;
var currentAnimation = 1;
var editor_isItem = true;
var editor_name = "BouncingObject";
var editor_args_names = ["healthValue","jumpStrength"];
var editor_args_values = [BouncingObject.prototype.healthValue,BouncingObject.prototype.jumpStrength];
var editor_args_types = ["number","number"];
var editor_args_options = [[-1,1,0.01],[0,600,50]];
var editor_args_descriptions = ["",""];
var editor_args_mode = [0,0];
var editor_args_component = ["NumericStepper","NumericStepper"];
function BouncingObject()
{
super();
}
function onAddToWorld()
{
this.originX = this.x;
this.originY = this.y;
}
function onAddToScene()
{
this.target.gotoAndStop(this.currentAnimation);
this.velocity.x = this.velocity.y = 0;
this.getUpdates();
}
function onRemoveFromScene()
{
this.cancelUpdates();
this.moveTo(this.originX,this.originY,0);
this.contact = null;
}
function update(elapsed)
{
if(this.immobilized)
{
if(!(this.immobilized = Math.max(this.immobilized - elapsed,0)))
{
this.setAnimation("restore");
}
}
if(!this.contact)
{
this.velocity.y += this.gravity * elapsed;
this.collision = false;
this.checkCollisions(elapsed);
this.moveBy(this.velocity.x * elapsed,this.velocity.y * elapsed,0);
}
else if(!this.immobilized && (this.contactTime = Math.max(this.contactTime - elapsed,0)) == 0)
{
this.velocity.y = - this.jumpStrength;
this.setAnimation("jump");
GameSound.playSound("spring");
this.contact = null;
}
}
function setContact(edge)
{
this.contact = edge;
this.contactTime = this.contactTimeAllow;
}
function checkCollision(obj)
{
var _loc3_ = undefined;
switch(obj.classID & 4294901760)
{
case SSGlobal.CLSID_SHAPE:
if(!this.contact && (_loc3_ = SSCollision.sweepSphereToStaticShape(this,obj)))
{
var _loc4_ = this.velocity.__get__length();
if(!this.immobilized)
{
this.setAnimation("still");
}
this.setContact(_loc3_.edge);
this.velocity.x = 0;
this.velocity.y = 0;
this.collision = true;
}
break;
case SSGlobal.CLSID_MAINCHAR:
if(SSCollision.sweepSphereToSphere(this,obj,true))
{
return this.onCollision(obj);
}
break;
}
}
function immobilize()
{
this.velocity.y = -100;
this.velocity.x = 0;
this.contact = null;
GameSound.playSound("enemyhit");
this.setAnimation("Immobile");
this.immobilized = this.immobilizeTime;
}
function setAnimation(anim)
{
this.target.gotoAndStop(this.currentAnimation = anim);
}
function onCollision(obj)
{
if(!this.inScene || this.immobilized)
{
return undefined;
}
if(obj.active && (obj.classID & 4294901760) == SSGlobal.CLSID_MAINCHAR)
{
if(obj.classID == SSGlobal.CLSID_VEHICLE || obj.shield || obj.y < this.y && obj.velocity.y >= 0)
{
this.immobilize();
obj.velocity.y *= -0.5;
obj.velocity.x *= 1.1;
}
else if(!this.immobilized)
{
obj.shiftHealth(this.healthValue,this);
}
}
}
}